package jdk8.calender;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;
/*
工具类:
Period类:计算日期间隔(年月日)
Duration类:计算时间间隔(时分秒)
ChronoUnit类:计算间隔(最强大的时间工具类)

 */
//计算活了多少天
public class Interval {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请按格式输入出生年月日:yyyy-mm-dd:");
        String birth=scanner.nextLine();
        //获取格式化对象
        DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-M-d");
        //格式化
        LocalDate births = LocalDate.parse(birth, dateTimeFormatter);
        LocalDate now=LocalDate.now();
        long days = ChronoUnit.DAYS.between(births, now);
        System.out.println(days);


    }
}
